package com.zy.springboot.com;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * <B>系统名称：</B><BR>
 * <B>模块名称：</B><BR>
 * <B>中文类名：</B>FastDFS分布式文件系统操作客户端<BR>
 * <B>概要说明：</B>FastDFS分布式文件系统操作客户端<BR>
 *
 * @Version: V1.0.0
 */
public final class BaseUtils {

    /**
     * 时间格式
     */
    private final static String DATEFORMAT = "yyyy-MM-dd HH:mm:ss";

    private final static String DATEHOURFORMAT = "HH:mm";
    private final static String DATEHOURSECONDFORMAT = "HH:mm:ss";
    private final static String DATEDAYFORMAT = "yyyy-MM-dd";

    /**
     * <B>构造方法</B><BR>
     */
    private BaseUtils() {

    }

    public final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());

    /**
     * 定义父级公共参数 供子类使用
     */
    public JSONObject jsonObject = new JSONObject();
    public JSONArray jsonArray = new JSONArray();


    public static void main(String[] arg) {
//        BaseUtils baseUtils = new BaseUtils();
//
//        List<JSONObject> list = new ArrayList<JSONObject>();
//        JSONObject obj = new JSONObject();
//        obj.put("name", "John");
//        list.add(obj);
//        System.out.println("成功返回List：" + baseUtils.succsessArrRespond(-0, "", list, 0));
//        System.out.println("成功返回JSONObject：" + baseUtils.succsessObjRespond(-1, "", obj, 1));
//        System.out.println("失败：" + baseUtils.errorrRespond(0, ""));
//        System.out.println("失败：" + baseUtils.errorrRespond());
    }

    public static class ResponseData {
        public e e = new e();

        class e {
            public int code;
            public String desc;
        }

        class data {
            public Integer count;

            public List<JSONObject> sendData;

            public data(List<JSONObject> sendData) {
                this.sendData = sendData;
            }

            public data(List<JSONObject> sendData, int count) {
                this.sendData = sendData;
                this.count = count;
            }
        }

        class b {
            public Integer count;

            public JSONObject sendData;

            public b(JSONObject sendData) {
                this.sendData = sendData;
            }

            public b(JSONObject sendData, int count) {
                this.sendData = sendData;
                this.count = count;
            }
        }

        public Object data;

        public ResponseData() {
            this.e.code = 0;
            this.e.desc = "";
            data = "";
        }

        public ResponseData(int e, String desc, String data) {
            this.e.code = e;
            this.e.desc = desc;
            data = data;
        }

        public ResponseData(String data) {
            this.e.code = 0;
            this.e.desc = "";
            data = data;
        }

        public ResponseData(int e, String desc) {
            this.e.code = e;
            this.e.desc = desc;
            data = new data(null);
        }

        public ResponseData(int e, String desc, List<JSONObject> sendData) {
            this.e.code = e;
            this.e.desc = desc;
            data = new data(sendData);
        }

        public ResponseData(int e, String desc, List<JSONObject> sendData, Integer count) {
            this.e.code = e;
            this.e.desc = desc;
            data = new data(sendData, count);
        }

        public ResponseData(int e, String desc, JSONObject sendData) {
            this.e.code = e;
            this.e.desc = desc;
            data = new b(sendData);
        }

        public ResponseData(int e, String desc, JSONObject sendData, Integer count) {
            this.e.code = e;
            this.e.desc = desc;
            data = new b(sendData, count);
        }
    }


    public static String succsessObjRespond() {
        return JSONObject.toJSONString(new ResponseData(0, "scussss"));
    }

    /**
     * @param success 成功消息
     * @Description:返回成功消息 <br/>
     * @return: java.lang.String
     * @throw:
     * @author: zhangwei
     * @createTime: 2017/10/31 15:47
     * @Version: V1.0.0
     */
    public static String succsessObjRespond(String success) {
        return JSONObject.toJSONString(new ResponseData(0, success));
    }

    public static String succsessObjRespond(JSONObject sendData) {
        return JSONObject.toJSONString(new ResponseData(0, "", sendData));
    }

    public static String succsessObjTimeRespond(JSONObject sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEFORMAT);
    }

    public static String succsessObjHourRespond(JSONObject sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEDAYFORMAT);
    }
    public static String succsessDocRespond(JSONObject sendData) {
        return JSONObject.toJSONStringWithDateFormat(sendData, DATEDAYFORMAT);
    }

    public static String succsessObjRespond(JSONObject sendData, Integer count) {
        return JSONObject.toJSONString(new ResponseData(0, "", sendData, count));
    }

    public static String succsessObjRespond(int code, String data, JSONObject sendData, Integer count) {
        return JSONObject.toJSONString(new ResponseData(code, data, sendData, count));
    }


    // 失败的信息

    public static String errorrRespond() {
        return JSONObject.toJSONString(new ResponseData(1, "error"));
    }

    public static String errorrRespond(String desc) {
        return JSONObject.toJSONString(new ResponseData(1, desc));
    }

    public static String errorrRespond(int code, String desc) {
        return JSONObject.toJSONString(new ResponseData(code, desc));
    }

    public static String errorrRespond(int code, String data, List<JSONObject> sendData) {
        return JSONObject.toJSONString(new ResponseData(code, data, sendData));
    }

    public static String errorrRespond(int code, String desc, JSONObject sendData) {
        return JSONObject.toJSONString(new ResponseData(code, desc, sendData));
    }

    public static String errorrRespond(int code, String data, List<JSONObject> sendData, Integer count) {
        return JSONObject.toJSONString(new ResponseData(code, data, sendData, count));
    }

    public static String errorrRespond(String data, List<JSONObject> sendData) {
        return JSONObject.toJSONString(new ResponseData(1, data, sendData, 0));
    }


    // TODO 成功的List

    public static String succsessArrRespond() {
        return JSONObject.toJSONString(new ResponseData(0, "scussss"));
    }

    public static String succsessArrRespond(List<JSONObject> sendData) {
        return JSONObject.toJSONString(new ResponseData(0, "", sendData));
    }

    public static String succsessArrTimeRespond(List<JSONObject> sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEFORMAT);
    }

    public static String succsessArrTimeRespond(List<JSONObject> sendData, Integer count) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData, count), DATEFORMAT);
    }

    public static String succsessArrRespond(List<JSONObject> sendData, Integer count) {
        return JSONObject.toJSONString(new ResponseData(0, "", sendData, count));
    }

    public static String succsessArrRespond(List<JSONObject> sendData, String desc) {
        return JSONObject.toJSONString(new ResponseData(0, desc, sendData, 0));
    }

    public static String succsessArrRespond(int code, String data, List<JSONObject> sendData, Integer count) {
        return JSONObject.toJSONString(new ResponseData(code, data, sendData, count));
    }

    public static String succsessArrHourTimeRespond(JSONObject jsonObject) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", jsonObject), DATEHOURFORMAT);
    }

    public static String succsessArrHourTimeRespond(List<JSONObject> sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEHOURFORMAT);
    }

    public static String succsessArrSecondTimeRespond(List<JSONObject> sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEHOURSECONDFORMAT);
    }

    public static String succsessArrSecondTimeRespond(JSONObject jsonObject) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", jsonObject), DATEHOURSECONDFORMAT);
    }

    public static String succsessArrYearTimeRespond(List<JSONObject> sendData) {
        return JSONObject.toJSONStringWithDateFormat(new ResponseData(0, "", sendData), DATEDAYFORMAT);
    }
}